I'm gonna overwrite a lot of this notebook's old content. I changed the way I'm calculating wt, and wanna test that my training worked.
In [53]:
from pearce.emulator import *
from pearce.mocks import cat_dict
import numpy as np
from os import path
In [54]:
import matplotlib
#matplotlib.use('Agg')
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
In [55]:
from GPy.models import GPKroneckerGaussianRegression, GPRegression
from GPy.kern import *
import h5py
In [56]:
training_file = '/home/users/swmclau2/scratch/xi_gg_zheng07_cosmo_v3/PearceXiggCosmo.hdf5'
test_file = '/home/users/swmclau2/scratch/xi_gg_zheng07_cosmo_test_v3/PearceXiggCosmoTest.hdf5'
In [57]:
f = h5py.File(training_file, 'r')
In [58]:
Ys = []
rbin = 0
for i in xrange(40):
Ys.append(f['cosmo_no_%02d'%i]['a_1.000']['obs'].value[:, rbin])
In [59]:
n_hods = 100
start_idx = 0
X1 = f.attrs['cosmo_param_vals']
X2 = f.attrs['hod_param_vals'][start_idx:start_idx+n_hods]
Y = np.vstack(Ys)[:, start_idx:start_idx+n_hods]
In [60]:
X1[-10:,:]
Out[60]:
In [61]:
X2[-10:,:]
Out[61]:
In [62]:
X1.shape, X2.shape, Y.shape
Out[62]:
In [63]:
# how to add training errors?
In [64]:
c = np.eye(X1.shape[0])
print c.shape
print c.diagonal()
In [65]:
K1 = RBF(input_dim = 7, ARD=False)#+ Linear(input_dim = 7, ARD = False) + Bias(input_dim=7)# + White(input_dim=7)
K2 = RBF(input_dim=4, ARD = False)#Linear(input_dim = 4, ARD = True) + Bias(input_dim=4)# + White(input_dim=4)
In [66]:
model = GPKroneckerGaussianRegression(X1, X2, Y,K1, K2 )
In [67]:
model.optimize_restarts(num_restarts=10)
Out[67]:
In [85]:
model.kern1
Out[85]:
In [68]:
K1.param_array
Out[68]:
In [69]:
K2.param_array
Out[69]:
In [70]:
f2 = h5py.File(test_file, 'r')
In [71]:
Y2s = []
for i in xrange(35):
Y2s.append(f2['cosmo_no_%02d'%i]['a_1.000']['obs'].value[:, rbin])
In [72]:
testX1 = f2.attrs['cosmo_param_vals']
testX2 = f2.attrs['hod_param_vals']
testY = np.vstack(Y2s)
In [73]:
print testX1.shape
print testX2.shape
print testY.shape
In [74]:
print testX1[0,:]
print testX2[0,:]
In [75]:
predY, _ = model.predict(testX1, testX2)
In [76]:
print predY.shape
In [77]:
print predY[0]
In [78]:
np.median( np.abs( (10**predY[:,0] - 10**testY.flatten(order='F'))/10**testY.flatten(order='F') ) )
Out[78]:
In [79]:
np.mean( np.abs( (10**predY[:,0] - 10**testY.flatten(order='F'))/10**testY.flatten(order='F') ) )
Out[79]:
In [80]:
predY[:,0]
Out[80]:
In [81]:
testY.flatten(order='F')
Out[81]:
In [82]:
k_dict = K1.to_dict()
In [83]:
k_dict['parts'].keys()
In [ ]: